package cosc617_blackteam;

import java.util.ArrayList;
import java.util.Iterator;
/**
 * 
 * @author sherbahadur
 *This class iterates only the orders based on individual customer information :
 */

public class OrderOfIndividualCustomerIterator implements Iterator<Order> {
int currentIndex=0;
private ArrayList<Order>items=new ArrayList<Order>();

private Customer customer;
public OrderOfIndividualCustomerIterator(ArrayList<Order> listOfOrders, Customer c){
 items.addAll(listOfOrders);
 this.customer=c;
}
/**
 * this simply checks if there is order for a customer with that name
 */
 @Override
public boolean hasNext() {
boolean customerOrderFound=true;
while(currentIndex<items.size()){
if(items.get(currentIndex).customer().equals(customer)){
customerOrderFound=true;
return customerOrderFound;
}currentIndex++;

}customerOrderFound=false;
 return customerOrderFound;
 }
/**
 * return item ordered by a given customer based on customer info
 */
 @Override
 public Order next() {
Order item=null;
if(hasNext()){
	item=items.get(currentIndex);
			currentIndex++;
}
 
return item;

 }
/**
 * remove all the old orders except the currently active ones
 */
@Override
 public void remove() {
 if(hasNext()){
	items.remove(currentIndex);

 }
}


}

